<?php
	include("session.inc");
    include("dbconn.inc");
	include("dbfuc.inc");
	require "config.php";
	
	//$logname=$HTTP_POST_VARS["membername"];
	//$password=$HTTP_POST_VARS["password"];
	$logname=$_POST["membername"];
	$password=$_POST["password"];
	$id=0;
	$username="";
	$uid=0;
	$renewalno=0;
	$errormsg="";
	$errorstep=false;
	if($logname==null) 
		$logname="";
	if($password==null) 
	  	$password="";
//MD 5 ENCRIPTION
	$password= md5($password);		
	//echo $password;
	//$today=date('Y-m-d');
				/* check user is exist in admin */
	$query  = "select pc_username,c_password from  mlm_login WHERE pc_username = '$logname' and c_password='$password'  ";
	$result = mysql_query($query); 
	$numR   = mysql_num_rows($result);
		//echo 'Before  FIRST if \n';
		//echo $query;
	if ($numR == 1) 
	{ 
		$numR=$numR-1;
		$username=mysql_result($result,$numR,"pc_username");
		$sql="select pn_id,n_renewal_no from mlm_master where c_username='$logname' and c_enabled_ind in('1','3') order by pn_id";
		$bcresult=mysql_query($sql);
		$bc_numR=mysql_num_rows($bcresult);
	 	//echo "Before if";
		if($bc_numR >=1)
		{
			//echo "inside if";
			$bc_numR=$bc_numR-1;		
			
			
			$renewalno=mysql_result($bcresult,$bc_numR,"n_renewal_no");
			$uid=mysql_result($bcresult,$bc_numR,"pn_id");
			if($renewalno==1) {
					//echo "SC";
				//echo "login was successfull....";
				$errorstep=true;
				$_SESSION['user']=$username;
				$_SESSION["curid"]=$uid;
				$_SESSION["dbconnection"]=$db;
				//echo "login was successfull....";
				//echo $_SESSION["dbconnection"];
			}
			if($renewalno==0) {
				//echo "fai";
				$errorstep=false;
				$errormsg="*Your ID is not Activated or Disabled";
			}

		}
	} else {  
		//echo "\n inside else";
		$errorstep=false;
		$errormsg="Invalid User Name/Password";
	}  
	//echo $errorstep;
	if($errorstep==true) {
		//header("Location: validation_success.php");
		echo "<script>document.location.href='validation_success.php'</script>";
	} else {
		//header("location:index.php?error=$errormsg");
		echo "<script>document.location.href='index.php?error=$errormsg'</script>";
		//echo $errormsg;		
	}
?>